﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agr.CQRS.Infrastructure.Orm;
using NHibernate.Criterion;

namespace Agr.CQRS.Infrastructure.Events
{
    class QueryGetEventsToRebuildAggregate : CriteriaQuery<StoredDomainEvent>
    {
        public QueryGetEventsToRebuildAggregate()
        {
            Criteria.AddOrder(Order.Asc("Version"));
        }

        public QueryGetEventsToRebuildAggregate AggregateRootIdIs(Guid id)
        {
            Criteria.Add(Expression.Eq("AggregateRootId", id));
            return this;
        }

        public QueryGetEventsToRebuildAggregate UpToVersion(int version)
        {
            //version + 1, because version in event is version before applying the event
            Criteria.Add(Expression.Le("Version", version + 1));
            return this;
        }
    }
}
